package com.company.bookstore.controller.book_module;

import com.company.bookstore.common.result.MvcResult;
import com.company.bookstore.entities.book_module.Book;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BookAdvice {

    @ResponseBody
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public MvcResult<Object> handleException(Exception e){
        return MvcResult.ADD_FAIL;
    }

    @ResponseBody
    @ExceptionHandler(DuplicateKeyException.class)
    public MvcResult<Object> handleDuplicateKeyException(Exception e){
        return MvcResult.DuplicateException;
    }

}
